package com.twu.biblioteca;

import java.io.Serializable;
import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * User: kush jain
 * Date: 7/5/13
 * Time: 2:09 AM
 * To change this template use File | Settings | File Templates.
 */
public class UserManager implements Serializable {
      private ArrayList allUsers = new ArrayList();
      public String addUser(User newUser)
      {
          allUsers.add(newUser);
          return "Added User " + Presenter.newLine + newUser.print();
      }

        public  String  removeUser(String userName)
        {
            int i;
            for(i=0;i<allUsers.size();i++)
            {
                User currentUser = (User)allUsers.get(i);
                if(currentUser.getUsername().equals(userName))
                {
                    break;
                }
            }
            if(i==allUsers.size())
                return "User Not Found";

            User deluser = (User)allUsers.remove(i);
            return "Removed User " + deluser.print();
        }
      public boolean authenticate(String username,String password){
          for(int i=0;i<allUsers.size();i++)
          {
              if(((User)allUsers.get(i)).matchLoginData(username,password))
                  return true;
          }
          return false;
      }
      public User getUser(String username)
      {
          for(int i=0;i<allUsers.size();i++)
          {
              if(((User)allUsers.get(i)).getUsername().equals(username))
                  return ((User)allUsers.get(i));
          }
          return null;
      }


}
